<template>
	<view>
		<u-card :thumb="base+reactive.avatarUrl" :title="reactive.name">
			<view slot="body">
				<view>从业年限：{{reactive.workStartAt}}</view>
				<view>服务人数：{{reactive.serviceTimes}}</view>
				<view>咨询人数：{{reactive.serviceTimes}}</view>
				<view>法律专长：{{reactive.legalExpertiseName}}</view>
				<view>好评率：{{reactive.favorableRate}}%</view>
			</view>
		</u-card>
		<uni-group>
			<u-dropdown ref="dropdown" >
				<u-dropdown-item  :title="name == ''?'点击选择问题类型':name">
					<view class="u-p-10" style="width: 100%;background-color: #fff;height: 50vh;">
						<view class="item-container">
							<view class="thumb-box" v-for="(item1, index1) in quanbu"   :key="index1" @click="tolist(item1.id,item1.name)">
								<image class="item-menu-image" :src="base+item1.imgUrl" mode=""></image>
								<view class="item-menu-name">{{item1.name}}</view>
							</view>
						</view>
					</view>
				</u-dropdown-item>
			</u-dropdown>
			<uni-group title="问题描述">
				<uni-easyinput type="textarea" placeholder="问题描述" v-model="value"></uni-easyinput>
			</uni-group>
			<uni-group title="联系电话">
				<uni-easyinput  placeholder="问题描述" v-model="value2"></uni-easyinput>
			</uni-group>
			<uni-group title="上传图片">
				<uni-file-picker @select="select" :auto-upload="false" file-mediatype="image" limit="1"></uni-file-picker>
			</uni-group>
			<button @click="postwen"> 提交</button>
		</uni-group>
	</view>
</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				base:api.baseurl,
				reactive:'',
				quanbu:[],
				//类型id
				getleiid:'',
				img: '',
				value:'',
				value2:'',
				id:'',
				name:'',
			}
		},
		onLoad(options) {
			this.getxian(options.id)
			this.id = options.id
			this.getfen()
		},
		methods: {
			select(e) {
				let img = e.tempFilePaths[0]
				console.log(img)
				this.shang(img)
			},
			shang(img) {
				console.log(img)
				let token = uni.getStorageSync('token')
				uni.uploadFile({
					url: this.base + '/prod-api/common/upload',
					header: {
						'authorization': token,
					},
					name: 'file',
					filePath: img,
					success: (res) => {
						let date = JSON.parse(res.data)
						this.img = '/prod-api' + date.fileName
						console.log(this.img)
					}
			
				})
			},
			postwen() {
				this.$post(this.base + '/prod-api/api/lawyer-consultation/legal-advice', {
					"lawyerId": this.id,
					"legalExpertiseId": this.getleiid,
					"content": this.value,
					"imageUrls":this.img,
					phone:this.value2
				}).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: "提交成功",
						})
						setTimeout(() => {
							uni.navigateTo({
								url: 'zhixu'
							})
						}, 500)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			getxian(id){
				this.$get(this.base+'/prod-api/api/lawyer-consultation/lawyer/'+id).then((res)=>{		
					this.reactive = res.data
				})
			},
			getfen(){
				this.$get(this.base+'/prod-api/api/lawyer-consultation/legal-expertise/list').then((res)=>{		
					this.quanbu = res.rows
				})
			},
			tolist(id,name){
				this.name = name
				this.getleiid = id
				this.$refs.dropdown.close()
			},
			
		}
	}
</script>

<style>
	.item-container {
		display: flex;
		flex-wrap: wrap;
	}
	
	.thumb-box {
		width: 25%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin-top: 20rpx;
	}
	
	.item-menu-image {
		width: 80rpx;
		height: 80rpx;
	}
</style>
